1
|
|
|
|
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
const expect = require('chai').expect; |
5
|
|
|
|
6
|
|
|
const specHelper = require('../lib/spec-helper'); |
7
|
|
|
const Sandcage = require('../..'); |
8
|
|
|
|
9
|
|
|
const RIGHT_KEY = specHelper.RIGHT_KEY; |
10
|
|
|
const WRONG_KEY = specHelper.WRONG_KEY; |
11
|
|
|
const REQUEST_ID = 'req_B8r09x8SucENLdGmHD8s08HDZDOEon'; |
12
|
|
|
const JOBS = [ |
13
|
|
|
{ |
14
|
|
|
"url": "http://cdn.sandcage.com/p/a/img/logo.jpg", |
15
|
|
|
"tasks": [ |
16
|
|
|
{ |
17
|
|
|
"actions": "save" |
18
|
|
|
}, |
19
|
|
|
{ |
20
|
|
|
"actions": "resize", |
21
|
|
|
"filename": "hello_world.jpg", |
22
|
|
|
"width": 200 |
23
|
|
|
}, |
24
|
|
|
{ |
25
|
|
|
"actions": "crop", |
26
|
|
|
"coords": "10,10,50,50" |
27
|
|
|
}, |
28
|
|
|
{ |
29
|
|
|
"reference_id": "123456789", |
30
|
|
|
"actions": "rotate", |
31
|
|
|
"degrees": 90 |
32
|
|
|
}, |
33
|
|
|
{ |
34
|
|
|
"actions": "cover", |
35
|
|
|
"width": 60, |
36
|
|
|
"height": 60, |
37
|
|
|
"cover": "middle,center" |
38
|
|
|
} |
39
|
|
|
] |
40
|
|
|
}, |
41
|
|
|
{ |
42
|
|
|
"url": "http://cdn.sandcage.com/p/a/img/header_404.png", |
43
|
|
|
"tasks": [ |
44
|
|
|
{ |
45
|
|
|
"actions": "resize", |
46
|
|
|
"height": 30 |
47
|
|
|
} |
48
|
|
|
] |
49
|
|
|
} |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
const CALLBACK_URL = 'http://www.example.com/callback_url'; |
53
|
|
|
|
54
|
|
|
const FILES = [ |
55
|
|
|
{ |
56
|
|
|
"reference_id": "40s" |
57
|
|
|
}, |
58
|
|
|
{ |
59
|
|
|
"file_token": "file_hd869xazuhwm62f9rc6qjcj7u_v6x8akrqgpi" |
60
|
|
|
} |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
describe('Sandcage with callback', () => { |
64
|
|
|
|
65
|
|
|
const sandcage = new Sandcage({apiKey: RIGHT_KEY}); |
66
|
|
|
const sandcageWithWrongKey = new Sandcage({apiKey: WRONG_KEY}); |
67
|
|
|
|
68
|
|
|
before('init nock', () => { |
69
|
|
|
specHelper.initNock(); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
describe('getInfo', () => { |
73
|
|
|
|
74
|
|
|
let response; |
75
|
|
|
|
76
|
|
|
before('call getInfo', (done) => { |
77
|
|
|
sandcage |
78
|
|
|
.getInfo({'request_id': REQUEST_ID}, (err, result) => { |
79
|
|
|
response = result; |
80
|
|
|
done(); |
81
|
|
|
}); |
82
|
|
|
}); |
83
|
|
|
|
84
|
|
|
it('should contain status', () => { |
85
|
|
|
return expect(response.status).to.exist; |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
it('status should be "success"', () => { |
89
|
|
|
expect(response.status).to.be.equal('success'); |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
it('files should be an array', () => { |
93
|
|
|
expect(response.files).to.be.an('array'); |
94
|
|
|
}); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
describe('getInfo with wrong key', () => { |
98
|
|
|
|
99
|
|
|
let response; |
100
|
|
|
|
101
|
|
|
before('call getInfo', (done) => { |
102
|
|
|
sandcageWithWrongKey |
103
|
|
|
.getInfo({'request_id': REQUEST_ID}, (err) => { |
104
|
|
|
response = err; |
105
|
|
|
done(); |
106
|
|
|
}); |
107
|
|
|
}); |
108
|
|
|
|
109
|
|
|
it('should catch error', () => { |
110
|
|
|
return expect(response).to.exist; |
111
|
|
|
}); |
112
|
|
|
}); |
113
|
|
|
|
114
|
|
|
describe('listFiles', () => { |
115
|
|
|
|
116
|
|
|
let response; |
117
|
|
|
|
118
|
|
|
before('call listFiles', (done) => { |
119
|
|
|
sandcage |
120
|
|
|
.listFiles({directory: 'img/'}, (err, result) => { |
121
|
|
|
response = result; |
122
|
|
|
done(); |
123
|
|
|
}); |
124
|
|
|
}); |
125
|
|
|
|
126
|
|
|
it('should contain status', () => { |
127
|
|
|
return expect(response.status).to.exist; |
128
|
|
|
}); |
129
|
|
|
|
130
|
|
|
it('status should be "success"', () => { |
131
|
|
|
expect(response.status).to.be.equal('success'); |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
it('files should be an array', () => { |
135
|
|
|
expect(response.files).to.be.an('array'); |
136
|
|
|
}); |
137
|
|
|
}); |
138
|
|
|
|
139
|
|
|
describe('listFiles with wrong key', () => { |
140
|
|
|
|
141
|
|
|
let response; |
142
|
|
|
|
143
|
|
|
before('call listFiles', (done) => { |
144
|
|
|
sandcageWithWrongKey |
145
|
|
|
.listFiles({directory: 'img/'}, (err) => { |
146
|
|
|
response = err; |
147
|
|
|
done(); |
148
|
|
|
}); |
149
|
|
|
}); |
150
|
|
|
|
151
|
|
|
it('should catch error', () => { |
152
|
|
|
return expect(response).to.exist; |
153
|
|
|
}); |
154
|
|
|
}); |
155
|
|
|
|
156
|
|
|
describe('scheduleTasks', () => { |
157
|
|
|
|
158
|
|
|
let response; |
159
|
|
|
|
160
|
|
|
before('call scheduleTasks', (done) => { |
161
|
|
|
sandcage |
162
|
|
|
.scheduleFiles({jobs: JOBS}, CALLBACK_URL, (err, result) => { |
163
|
|
|
response = result; |
164
|
|
|
done(); |
165
|
|
|
}); |
166
|
|
|
}); |
167
|
|
|
|
168
|
|
|
it('should contain status', () => { |
169
|
|
|
return expect(response.status).to.exist; |
170
|
|
|
}); |
171
|
|
|
|
172
|
|
|
it('status should be "success"', () => { |
173
|
|
|
expect(response.status).to.be.equal('success'); |
174
|
|
|
}); |
175
|
|
|
|
176
|
|
|
it('tasks should be an array', () => { |
177
|
|
|
expect(response.tasks).to.be.an('array'); |
178
|
|
|
}); |
179
|
|
|
}); |
180
|
|
|
|
181
|
|
|
describe('scheduleTasks with wrong key', () => { |
182
|
|
|
|
183
|
|
|
let response; |
184
|
|
|
|
185
|
|
|
before('call scheduleTasks', (done) => { |
186
|
|
|
sandcageWithWrongKey |
187
|
|
|
.scheduleFiles({jobs: JOBS}, CALLBACK_URL, (err, result) => { |
188
|
|
|
response = err; |
189
|
|
|
done(); |
190
|
|
|
}); |
191
|
|
|
}); |
192
|
|
|
|
193
|
|
|
it('should catch error', () => { |
194
|
|
|
return expect(response).to.exist; |
195
|
|
|
}); |
196
|
|
|
}); |
197
|
|
|
|
198
|
|
|
describe('destroyFiles', () => { |
199
|
|
|
|
200
|
|
|
let response; |
201
|
|
|
|
202
|
|
|
before('call destroyFiles', (done) => { |
203
|
|
|
sandcage |
204
|
|
|
.destroyFiles({files: FILES}, CALLBACK_URL, (err, result) => { |
205
|
|
|
response = result; |
206
|
|
|
done(); |
207
|
|
|
}); |
208
|
|
|
}); |
209
|
|
|
|
210
|
|
|
it('should contain status', () => { |
211
|
|
|
return expect(response.status).to.exist; |
212
|
|
|
}); |
213
|
|
|
|
214
|
|
|
it('status should be "success"', () => { |
215
|
|
|
expect(response.status).to.be.equal('success'); |
216
|
|
|
}); |
217
|
|
|
|
218
|
|
|
}); |
219
|
|
|
|
220
|
|
|
describe('destroyFiles with wrong key', () => { |
221
|
|
|
|
222
|
|
|
let response; |
223
|
|
|
|
224
|
|
|
before('call destroyFiles', (done) => { |
225
|
|
|
sandcageWithWrongKey |
226
|
|
|
.destroyFiles({files: FILES}, CALLBACK_URL, (err, result) => { |
227
|
|
|
response = err; |
228
|
|
|
done(); |
229
|
|
|
}); |
230
|
|
|
}); |
231
|
|
|
|
232
|
|
|
it('should catch error', () => { |
233
|
|
|
return expect(response).to.exist; |
234
|
|
|
}); |
235
|
|
|
}); |
236
|
|
|
|
237
|
|
|
}); |
238
|
|
|
|
239
|
|
|
|